#include<iostream> 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
   int n,a[210],b[210],mmin,p0,mmax,p1;
   while(cin>>n) {
     for(int i=0;i<n;i++)
     {   cin>>a[i];
         b[i]=a[i];
     }
     sort(a,a+n);
     for(int i=0;i<n;i++)
       if(a[0]==b[i])  {p0=i;break;}
     for(int i=n-1;i>=0;i--)
       if(a[n-1]==b[i])  {p1=i;break;}
     //cout<<p0<<" "<<p1<<endl;
      if(p0<p1)  cout<<p0+n-1-p1<<endl;
      else cout<<n-1-p1+p0-1<<endl;
   }
   return 0;
}
